<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="报销状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择报销状态" clearable>
          <el-option v-for="dict in dict.type.imburse_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="报销类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择报销类型" clearable>
          <el-option v-for="dict in dict.type.reimburse_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <!--<el-form-item label="申请人姓名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入报销申请人姓名"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>-->
      <el-form-item label="请款人名称" prop="qkrmc">
        <el-input v-model="queryParams.qkrmc" placeholder="请输入请款人名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="请款事由" prop="qksy">
        <el-input v-model="queryParams.qksy" placeholder="请输入请款事由" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="资金用途" prop="zjyt">
        <el-input v-model="queryParams.zjyt" placeholder="请输入资金用途" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--<el-form-item label="报销日期" prop="imburseDate">
        <el-date-picker clearable v-model="queryParams.imburseDate"
                        type="date" value-format="yyyy-MM-dd" placeholder="请选择报销日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="发票金额" prop="taxMoney">
        <el-input v-model="queryParams.taxMoney" placeholder="请输入发票金额"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['develop:GoodsReimbursement:add']">新增报销
        </el-button>
      </el-col>-->
      <!--<el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                   @click="handleUpdate" v-hasPermi="['develop:GoodsReimbursement:edit']">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
          <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                     v-hasPermi="['develop:GoodsReimbursement:remove']">删除
          </el-button>
        </el-popconfirm>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini"
                   @click="handleExport" v-hasPermi="['develop:GoodsReimbursement:export']">导出
        </el-button>
      </el-col>-->
      <!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange"
      :max-height="tableMaxHeight">
      <!--      <el-table-column label="主键" align="center" prop="id"/>-->
      <el-table-column label="报销状态" align="center" prop="status" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.imburse_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="报销类型" align="center" prop="type" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.reimburse_type" :value="scope.row.type" />
        </template>
      </el-table-column>
      <!--<el-table-column label="报销人" align="center" prop="userId"/>-->
      <el-table-column label="申请人姓名" align="center" prop="userName"  />
      <el-table-column label="请款人人姓名" align="center" prop="qkrmc"  />
      <el-table-column label="报销日期" align="center" prop="imburseDate" width="180" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.imburseDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报销金额" align="center" prop="imburseMoney"  />
      <el-table-column label="剩余发放金额" align="center" prop="remRemain"  />
      <!--<el-table-column label="关联发票" align="center" prop="taxId"/>
      <el-table-column label="发票号码" align="center" prop="taxNo"/>
      <el-table-column label="发票金额" align="center" prop="taxMoney"/>-->
      <el-table-column label="请款事由" align="center" prop="qksy" show-overflow-tooltip />
      <el-table-column label="资金用途" align="center" prop="zjyt" show-overflow-tooltip />
      <!--      <el-table-column label="报销描述" align="center" prop="infomation"/>-->
      <!--<el-table-column label="关联商品id" align="center" prop="goodsIds"/>
      <el-table-column label="附件" align="center" prop="file"/>
              <el-table-column label="报销状态" align="center" prop="status">
                  <template slot-scope="scope">
                          <dict-tag :options="dict.type.imburse_status" :value="scope.row.status"/>
                  </template>
              </el-table-column>
      <el-table-column label="备注" align="center" prop="remark"/>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleUpdate(scope.row)">查看详情
          </el-button>
          <!--<el-button  type="text" icon="el-icon-download"
                     @click="handleExport(scope.row)">导出word
          </el-button>-->
          <el-button size="mini" type="text" icon="el-icon-download" @click="exportExcel(scope.row)">导出
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-download" @click="exportFksqd(scope.row)">付款申请单
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!--    <goodsReimbursement-form ref="GoodsReimbursementForm" @ok="getList"></goodsReimbursement-form>-->
    <goods-reimbursement-form-for-view ref="formForOrderView" @ok="getList"></goods-reimbursement-form-for-view>
  </div>
</template>

<script>
  import {
    deleteAction,
    downloadFile,
    getAction
  } from '@/api/manage'
  import GoodsReimbursementFormForView from "./module/GoodsReimbursementFormForView";
  // import GoodsReimbursementForm from '@/views/develop/goodsReimbursement/module/GoodsReimbursementForm'

  export default {
    name: "GoodsReimbursementListAll",
    components: {
      // GoodsReimbursementForm,
      GoodsReimbursementFormForView,
    },
    dicts: ['reimburse_type', 'imburse_status'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        id: "",
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 报销发票信息管理表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          qkrmc: null,
          qksy: null,
          zjyt: null,
          type: null,
          userId: null,
          userName: null,
          imburseDate: null,
          taxId: null,
          taxNo: null,
          taxMoney: null,
          infomation: null,
          goodsIds: null,
          file: null,
          status: null,
        },
        url: {
          list: '/goodsReimbursement/goodsReimbursement/list',
          remove: '/goodsReimbursement/goodsReimbursement/',
          export: '/goodsReimbursementDetail/goodsReimbursementDetail/export',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      this.getList();
    },
    methods: {
      exportFksqd(id) {
        let that = this;
        that.loading = false;
        that.$confirm('是否确认导出付款申请单?', "确认", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          downloadFile('/goodsReimbursementDetail/goodsReimbursementDetail/exportFksqd', id);
        });
      },
      /** 查询报销发票信息管理列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      /*handleAdd() {
          this.$refs.form.handleAdd();
      },*/
      /** 修改按钮操作 */
      handleUpdate(row) {
        // this.$refs.GoodsReimbursementForm.handleUpdate(row);
        this.$refs.formForOrderView.handleUpdate(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.remove, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      /* handleExport() {
            this.download(this.url.export, {
                ...this.queryParams
            }, `goodsReimbursement_${new Date().getTime()}.xlsx`)
        },*/
      handleExport(id) {
        let that = this;
        //that.addDateRange(that.queryParams, that.id, id);
        downloadFile(that.url.export, that.queryParams);
      },
      exportExcel(id) {
        let that = this;
        that.loading = false;
        that.$confirm('是否确认导出报销申请信息表?', "确认", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          downloadFile('/goodsReimbursementDetail/goodsReimbursementDetail/exportExcel', id);
        });
      },

    }
  };
</script>
